package com.yike.user.controller;

import com.yike.user.entity.PrivacyAgreement;
import com.yike.user.param.PrivacyAgreementParam;
import com.yike.user.service.PrivacyAgreementService;
import com.yike.user.vo.PrivacyAgreementVo;
import lombok.extern.slf4j.Slf4j;
import com.yike.user.param.PrivacyAgreementPageParam;
import com.yike.common.base.BaseController;
import com.yike.common.api.ApiResult;
import com.yike.common.pagination.Paging;
import com.yike.common.api.IdParam;
import com.yike.common.log.Module;
import com.yike.common.log.OperationLog;
import com.yike.common.enums.OperationLogType;
import com.yike.common.api.Add;
import com.yike.common.api.Update;
import org.springframework.validation.annotation.Validated;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 隐私协议表 控制器
 *
 * @author Sakura
 * @since 2024-09-12
 */
@Slf4j
@RestController
@RequestMapping("/privacyAgreement")
@Module("user")
@Api(value = "隐私协议API", tags = {"隐私协议管理"})
public class PrivacyAgreementController extends BaseController {

    @Autowired
    private PrivacyAgreementService privacyAgreementService;

    /**
     * 添加隐私协议表
     */
    @PostMapping("/add")
    @OperationLog(name = "添加隐私协议", type = OperationLogType.ADD)
    @ApiOperation(value = "添加隐私协议", response = ApiResult.class)
    public ApiResult<Boolean> addPrivacyAgreement(@Validated(Add.class) @RequestBody PrivacyAgreementParam privacyAgreementParam) throws Exception {
        boolean flag = privacyAgreementService.savePrivacyAgreement(privacyAgreementParam);
        return ApiResult.result(flag);
    }

    /**
     * 修改隐私协议表
     */
    @PostMapping("/update")
    @OperationLog(name = "修改隐私协议", type = OperationLogType.UPDATE)
    @ApiOperation(value = "修改隐私协议", response = ApiResult.class)
    public ApiResult<Boolean> updatePrivacyAgreement(@Validated(Update.class) @RequestBody PrivacyAgreementParam privacyAgreementParam) throws Exception {
        boolean flag = privacyAgreementService.updatePrivacyAgreement(privacyAgreementParam);
        return ApiResult.result(flag);
    }

    /**
     * 删除隐私协议表
     */
    @PostMapping("/delete/{id}")
    @OperationLog(name = "删除隐私协议", type = OperationLogType.DELETE)
    @ApiOperation(value = "删除隐私协议", response = ApiResult.class)
    public ApiResult<Boolean> deletePrivacyAgreement(@PathVariable("id") Long id) throws Exception {
        boolean flag = privacyAgreementService.deletePrivacyAgreement(id);
        return ApiResult.result(flag);
    }

    /**
     * 获取隐私协议表详情
     */
    @GetMapping("/info/{id}")
    //@OperationLog(name = "隐私协议详情", type = OperationLogType.INFO)
    @ApiOperation(value = "隐私协议详情", response = PrivacyAgreement.class)
    public ApiResult<PrivacyAgreement> getPrivacyAgreement(@PathVariable("id") Long id) throws Exception {
        PrivacyAgreement privacyAgreement = privacyAgreementService.getById(id);
        return ApiResult.ok(privacyAgreement);
    }

    /**
     * 隐私协议表分页列表
     */
    @PostMapping("/getPageList")
    //@OperationLog(name = "隐私协议分页列表", type = OperationLogType.PAGE)
    @ApiOperation(value = "隐私协议分页列表", response = PrivacyAgreementVo.class)
    public ApiResult<Paging<PrivacyAgreementVo>> getPrivacyAgreementPageList(@Validated @RequestBody PrivacyAgreementPageParam privacyAgreementPageParam) throws Exception {
        Paging<PrivacyAgreementVo> paging = privacyAgreementService.getPrivacyAgreementPageList(privacyAgreementPageParam);
        return ApiResult.ok(paging);
    }

}

